<template>
  <page-header-wrapper>
    <a-card :bordered="false">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="24">
            <a-col :md="4" :sm="24">
              <a-form-item>
                <a-input placeholder="请输入商品名称" v-model="queryParam.name" />
              </a-form-item>
            </a-col>
            <a-col :md="4" :sm="24">
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="handleSearch(true)" icon="search">查询</a-button>
              </span>
            </a-col>
            <a-col :md="1" :sm="24" :offset="14">
              <a-button type="primary" icon="plus" @click="handleAdd">新增</a-button>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <s-table
        ref="table"
        size="default"
        rowKey="id"
        :columns="columns"
        :data="loadData"
        showPagination="auto"
        :pagination="pagination"
      >
        <template slot="head_img" slot-scope="text">
          <a-avatar shape="square" :size="64" icon="gift" :src="text" style="width:62px;height:62px" />
        </template>
        <template slot="type" slot-scope="text">
          {{ text | statusFilter }}
        </template>
        <template slot="status" slot-scope="status">
          <a-tag :color="kindsStatusDisplay(status)">{{ status | kindsStatusFilter }}</a-tag>
        </template>
        <a-badge :status="runTimeStatus(text)" :text="runTimeDisplay(text)" slot="runtime" slot-scope="text" />
        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="handleEdit(record)">编辑</a>
            <a-divider type="vertical" />
            <a @click="handleDelete(record)">删除</a>
          </template>
        </span>
      </s-table>

      <create-form ref="createModal" @ok="handleSearch" :addAction="addAction" :editAction="editAction" />
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { shareFeeList, shareFeeAdd, shareFeeEdit, shareFeeDel } from '@/api/shareFee'
import { activityTypeList } from '@/api/notControl'
import orderStatus from '@/mixins/orderStatus'
import CreateForm from './modules/ShareFeeForm'
import formTableMixin from '@/mixins/formTableMixin'
import runtimeStatus from '@/mixins/runtimeStatus'

const columns = [
  {
    title: '主图',
    dataIndex: 'head_img',
    scopedSlots: { customRender: 'head_img' }
  },
  {
    title: '名称',
    dataIndex: 'name'
  },
  {
    title: '市场价格',
    dataIndex: 'price',
    customRender (text) {
      return '￥' + text
    }
  },
  {
    title: '分享所需次数',
    dataIndex: 'share_number'
  },
   {
    title: '开始时间',
    dataIndex: 'atime'
  },
  {
    title: '结束时间',
    dataIndex: 'etime'
  },
  {
    title: '状态',
    dataIndex: 'runtime',
    scopedSlots: { customRender: 'runtime' }
  },
  {
    title: '是否上架',
    dataIndex: 'status',
    scopedSlots: { customRender: 'status' }
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: '150px',
    scopedSlots: { customRender: 'action' }
  }
]

const TYPE_STATUS = {
  1: '洗衣',
  2: '家电',
  3: '家政',
  4: '商城'
}

export default {
  name: 'ShareFeeList',
  mixins: [orderStatus, formTableMixin, runtimeStatus],
  components: {
    CreateForm
  },
  data () {
    this.columns = columns
    this.editAction = shareFeeEdit
    this.addAction = shareFeeAdd
    this.delAction = shareFeeDel
    this.listAction = parameter =>
      shareFeeList(parameter).then(res => {
        const data = res.data.data
        data.forEach(item => {
          const status = this.getRunTime(item.atime, item.etime)
          item.runtime = status
        })
        return res
      })
    return {}
  },
  filters: {
    statusFilter (key) {
      return TYPE_STATUS[key]
    }
  },
  created () {
    this.getActivityTypeList()
  },
  methods: {
    getActivityTypeList () {
      activityTypeList({ type: 4 }).then(res => {})
    }
  }
}
</script>
